package com.SFA.OrderManagement;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.FrameWork.Entity.PaymentEntity;
import com.SFA.R;

public class HistoryPaymentAdapter extends BaseAdapter{
	private List<PaymentEntity> list=null;
	private LayoutInflater inflater;
	
	public HistoryPaymentAdapter(List<PaymentEntity> list,Context context) {
		this.list=list;
		inflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHoder hoder=null;
		if(convertView==null){
			hoder=new ViewHoder();
			convertView = inflater.inflate(R.layout.payment_item, null);
			hoder.payamount=(TextView) convertView.findViewById(R.id.history_payamount);
			hoder.paytype=(TextView) convertView.findViewById(R.id.history_payType);
			hoder.paydate=(TextView) convertView.findViewById(R.id.history_paydate);
			convertView.setTag(hoder);
		}
		else
		{
			hoder = (ViewHoder)convertView.getTag();
		}
		PaymentEntity entity=list.get(position);
		
		hoder.payamount.setText(entity.PAYMENT_AMOUNT);
		String date=entity.PAYMENT_DATE;
		if(date!=null){
			hoder.paydate.setText(date.substring(0, 4)+"年"+date.substring(4, 6)+"月"+date.substring(6, 8)+"日  "+date.substring(8, 10)+"时"+date.substring(10, 12)+"分");
		}
		if(entity.PAYMENT_TYPE==0){
			hoder.paytype.setText("现金");
		}else if(entity.PAYMENT_TYPE==1){
			hoder.paytype.setText("刷卡");
		}
		
		return convertView;
	}

	private class ViewHoder
	{
		private TextView payamount;
		private TextView paytype;
		private TextView paydate;
	}
	
	
	
}
